package com.huike.stock_analysis.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.huike.stock_analysis.service.CapitalService;
/**
 * 
 * @author mzLEI
 *  资金统计接口
 */

@RestController
@CrossOrigin(value = "*")
@RequestMapping("/capital")
public class CapitalController {
	@Autowired
	private CapitalService cService;
	//资金净流入
	@RequestMapping("/capitalNetFlow")
	public String capitalNetFlow(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = cService.netFlow(stock);
		ObjectMapper mapper = new ObjectMapper();
		
		String result = "";
		try {
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	/*
	//平均同行涨跌幅
	@RequestMapping("/avrChange")
	public String avrChange() {
		return "";
	}
	*/
	//主力资金净流入
	@RequestMapping("/mainCapitalNetFlow")
	public String mainCapitalNetFlow(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = cService.mainNetFlow(stock);
		ObjectMapper mapper = new ObjectMapper();
		
		String result = "";
		try {
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	
	
	
	//平均同行净流入
	@RequestMapping("/avrNetFlow")
	public String avrNetFlow(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = cService.netFlowOfSame(stock);
		ObjectMapper mapper = new ObjectMapper();
		
		String result = "";
		try {
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	//平均同行主力净流入
	@RequestMapping("/avrMainNetFlow")
	public String avrMainNetFlow(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = cService.mainNetFlowOfSame(stock);
		ObjectMapper mapper = new ObjectMapper();
		
		String result = "";
		try {
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	
	//主力净流入占比
	@RequestMapping("/mainFlowRatio")
	public String mainFlowRatio(String stock) {
		if(stock == null) return "null";
		return cService.mainFlowRatio(stock);
	}
	
	//前十
	@RequestMapping("/top10")
	public String top10(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = cService.top10(stock);
		ObjectMapper mapper = new ObjectMapper();
		
		String result = "";
		try {
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	
	//后十
	@RequestMapping("/bottom10")
	public String bottom10(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = cService.bottom10(stock);
		ObjectMapper mapper = new ObjectMapper();
		
		String result = "";
		try {
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	//资金流向
	@RequestMapping("/flow")
	public String flow(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = cService.flow(stock);
		ObjectMapper mapper = new ObjectMapper();
		
		String result = "";
		try {
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	
	//涨跌幅排名前十
	@RequestMapping("/rank")
	public String rank(String stock) {
		if(stock == null) return "null";
		return cService.rank(stock);
	}

	
	
	

}
